
' common

Private Function create_SQLTranslateSingleColInfo( _
    ByRef tableName As String, ByRef colName As String) As SqlTranslateSingleColInfo
    Dim singleColInfo As SqlTranslateSingleColInfo
    Set singleColInfo = New SqlTranslateSingleColInfo

    ' 设置列所在的表名 token
    Dim tableNameToken As SqlToken
    Set tableNameToken = New SqlToken
    tableNameToken.Init tableName, SqlTokenType.STR_NAME

    singleColInfo.setTableNameToken tableNameToken

    ' 设置表的列名 token
    Dim colNameToken As SqlToken
    Set colNameToken = New SqlToken
    colNameToken.Init colName, SqlTokenType.STR_NAME

    singleColInfo.setColNameToken colNameToken

    Set create_SQLTranslateSingleColInfo = singleColInfo
End Function


' 基础测试
Private Sub test_SQLTranslateCompositeColInfo_base()
    Dim compositeColInfo As SqlTranslateCompositeColInfo
    Set compositeColInfo = New SqlTranslateCompositeColInfo

    ' Nothing 将不会被添加
    compositeColInfo.addColInfo Nothing

    ' 创建多个单列对象
    Dim colInfo1 As ISqlTranslateColInfo
    Dim colInfo2 As ISqlTranslateColInfo
    Dim colInfo3 As ISqlTranslateColInfo
    Set colInfo1 = create_SQLTranslateSingleColInfo("table1", "cx1")
    Set colInfo2 = create_SQLTranslateSingleColInfo("table2", "cx2")
    Set colInfo3 = create_SQLTranslateSingleColInfo("table3", "cx3")

    ' 添加多个列
    compositeColInfo.addColInfo colInfo1
    compositeColInfo.addColInfo colInfo2
    compositeColInfo.addColInfo colInfo3

    ' 检查被组合的列数
    Dim compositedCols As IObjArrayRef
    Set compositedCols = compositeColInfo.getColInfos()
    Debug.Assert compositedCols.Count = 3
    Debug.Assert compositedCols.Item(0) Is colInfo1
    Debug.Assert compositedCols.Item(1) Is colInfo2
    Debug.Assert compositedCols.Item(2) Is colInfo3

    ' 转换成接口类型
    Dim ic As ISqlTranslateColInfo
    Set ic = compositeColInfo

    ' 检查原始列名
    Debug.Assert ic.getOriginColName() = ""

    ' 尝试读写变换后的列名(默认是没有操作)
    Debug.Assert ic.getTranslatedColName() = ""
    ic.setTranslatedColName "xxxx"
    Debug.Assert ic.getTranslatedColName() = ""

    ' 检查原始表名(默认是没有的)
    Debug.Assert ic.getTableName() = ""

    ' 尝试读写表的别名(默认是没有操作)
    Debug.Assert ic.getTableAliasName() = ""
    ic.setTableAliasName("yyyyyy")
    Debug.Assert ic.getTableAliasName() = ""

    ' 检查当前列的别名
    Dim colAliasNameToken As SqlToken
    Set colAliasNameToken = New SqlToken
    colAliasNameToken.Init "XXX", SqlTokenType.STR_NAME
    Debug.Assert ic.getAliasName() = ""
    ic.setAliasNameToken colAliasNameToken
    Debug.Assert ic.getAliasName() = "XXX"
End Sub

